package com.spring.shops.service.impl;

import com.spring.shops.dao.TzProdTagMapper;
import com.spring.shops.model.entity.TzProdTag;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.model.vo.ProdTagVO2;
import com.spring.shops.service.ProdTagService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

@Service
public class ProdServiceImpl2 implements ProdTagService2 {
    @Autowired
    private TzProdTagMapper mapper;
    /**
     * 返回产品的标签列表
     * @return
     */
    @Override
    public ServerResponseEntityVoid<List<ProdTagVO2>> listTagList() {
        List<TzProdTag> tagList=mapper.listTagList();
        List<ProdTagVO2> tagListVO=new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //属性拷贝
        for (TzProdTag tag : tagList) {
            Boolean status = tag.getStatus();
            Integer status2= status ?1:0;
            Boolean isDefault = tag.getIsDefault();
            Integer isDefault2= isDefault?1:0;
            String createTime = sdf.format(tag.getCreateTime());
            String updateTime = sdf.format(tag.getUpdateTime());
            tagListVO.add(new ProdTagVO2(
                    tag.getId(), tag.getTitle(), tag.getShopId(),status2,isDefault2,
                    tag.getProdCount(),tag.getStyle(),tag.getSeq(),createTime,updateTime,null
            ));
        }
        return ServerResponseEntityVoid.success(tagListVO);
    }
}
